package tweeks.common.controller;

import java.io.IOException;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class CommonController {
	
	@RequestMapping(method=RequestMethod.GET, value="/main")
	public String loadMain() {
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String username = null;
		if (principal instanceof UserDetails) {
			username = ((UserDetails) principal).getUsername();
		}
		return "main/home";
	}
	
	@RequestMapping(method=RequestMethod.GET, value="/login")
	public String login() throws IOException {
		return "main/login";
	}
	
	@RequestMapping(method=RequestMethod.GET, value="/")
	public String mainForwarding() throws IOException {
		return "main/index";
	}
}
